<?php

class Application_View_Helper_SmartButton extends Zend_View_Helper_Abstract {

    public function smartButton($label, $url ='#', $options=array()) {
        $opts = '';
        $css = '';
        foreach ($options as $k => $v) {
            if ($k == 'class') {
                $css = $v;
                continue;
            }
            $opts .= $k . '=' . $v . ';';
        }
        $iconClass = '';
        $iconHtml = '';
        $labelTitle = $label;
        if (isset($options['icon']) && $options['icon']) {
            $css .= ' button_icon ';
            $iconHtml = '<img src="' . $options['icon'] . '" alt="icon" />';
        }
        if (isset($options['onlyIcon']) && $options['onlyIcon']) {
            $css .= ' button_only_icon ';
            $label = '';
        }
        if (isset($options['nobg']) && $options['nobg']) {
            $css .= ' button_nobg ';
        }
        if (isset($options['size']) && $options['size']) {
            $css .= ' btn-'.$options['size'].' ';
        }
        $noAjax = isset($options['noAjax']) ? $options['noAjax'] : false;
        $html = '<a class="smartButton btn button ' . ($noAjax ? 'noAjax' : 'ajax ') . ' ' . $css . '" rel="' . $opts . '" href="' . $url . '" title="'.$this->view->escape($labelTitle).'">' . $iconHtml . $label . '</a>';
        return $html;
    }

}